package priv.pront.code.robot.roboCom_pri_2021.zhi.fu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-07-13 14:59
 */
public class 人工智能数字翻译 {

    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static String s ;
    static int n;
    public static void main(String[] args) throws IOException {
        String[] ss = bf.readLine().split(" ");
        s = ss[0];
        n = Integer.parseInt(ss[1]);
        if (n == 10) {
            System.out.println(Long.toString(Long.parseLong(s), 27).toUpperCase());
        }else{
            System.out.println(Long.parseLong(s, 27));
        }
    }
}
